package com.aispeech.asr.webase.seaweedfs.client;

public enum ReplicationStrategy {
    /**
     * no replication
     */
    None("000"),
    /**
     * replicate once on the same rack
     */
    OnceOnSameRack("001"),
    /**
     * replicate once on a different rack, but same data center
     */
    OnceOnDifferentRack("010"),
    /**
     * replicate once on a different data center
     */
    OnceOnDifferentDC("100"),
    /**
     * replicate twice on two different data center
     */
    TwiceOnDifferentDC("200"),
    /**
     * replicate once on a different rack, and once on a different data center
     */
    OnceOnDifferentRackAndOnceOnDifferentDC("110");

    public final String parameterValue;

    ReplicationStrategy(String parameterValue) {
        this.parameterValue = parameterValue;
    }

    public static ReplicationStrategy fromParameterValue(String parameterValue) {
        // yes this is ugly
        switch (parameterValue) {
            case "000":
                return None;
            case "001":
                return OnceOnSameRack;
            case "010":
                return OnceOnDifferentRack;
            case "100":
                return OnceOnDifferentDC;
            case "200":
                return TwiceOnDifferentDC;
            case "110":
                return OnceOnDifferentRackAndOnceOnDifferentDC;
            default:
                throw new IllegalArgumentException("Unknown Replication Strategy: " + parameterValue);
        }
    }
}
